<template>
  <div class="header">
    <input type="text" placeholder="添加todo..." @keyup.enter="addTodo">
  </div>
</template>

<script>
export default {
  name: 'todoHeader',
  methods: {
    addTodo(e) {
      const {value} = e.target;
      e.target.value = '';
      if (!value.trim()) {
        return alert('todo 不能为空 ~');
      }
      this.$bus.$emit('addTodo', {
        id: Math.random().toString(36).slice(2),
        content: value.trim(),
        checked: false,
      });
    },
  },
};
</script>